package com.android.gpuimage;

import android.graphics.PointF;

/**
 * Created by @author winn on 18/8/1.
 */

public class g {
    public static final com.android.gpuimage.g a = new g(0, false);
    private static final float[] b = new float[]{0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f};
    private static final float[] c = new float[]{1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
    private static final float[] d = new float[]{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
    private static final float[] e = new float[]{0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f};
    private static final float[] f = new float[]{1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f};
    private static final float[] g = new float[]{0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f};
    private static final float[] h = new float[]{0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
    private static final float[] i = new float[]{1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
    private static com.android.gpuimage.g l = new g(90, false);
    private static com.android.gpuimage.g m = new g(180, false);
    private static com.android.gpuimage.g n = new g(270, false);
    private static com.android.gpuimage.g o = new g(0, true);
    private static com.android.gpuimage.g p = new g(90, true);
    private static com.android.gpuimage.g q = new g(180, true);
    private static com.android.gpuimage.g r = new g(270, true);
    private static PointF s = new PointF();
    private static PointF t = new PointF();
    private static PointF u = new PointF();
    private static PointF v = new PointF();
    private static float[] w = new float[8];
    private boolean j;
    private int k;

    private g(int i, boolean z) {
        this.k = i;
        this.j = z;
    }

    public static com.android.gpuimage.g a(int i) {
        return a.b(i);
    }

    private static com.android.gpuimage.g a(int i, boolean z) {
        int i2 = i;
        while (i2 < 0) {
            i2 += 360;
        }
        while (i2 >= 360) {
            i2 -= 360;
        }
        if (z) {
            switch (i2) {
                case 0:
                    return o;
                case 90:
                    return p;
                case 180:
                    return q;
                case 270:
                    return r;
                default:
                    throw new IllegalArgumentException("Invalid rotation value");
            }
        }
        switch (i2) {
            case 0:
                return a;
            case 90:
                return l;
            case 180:
                return m;
            case 270:
                return n;
            default:
                throw new IllegalArgumentException("Invalid rotation value");
        }
    }

    public boolean a() {
        return this.k == 90 || this.k == 270;
    }

    public com.android.gpuimage.g b(int i) {
        boolean z = true;
        int i2;
        switch (i) {
            case 0:
                return this;
            case 1:
                if (a()) {
                    i2 = this.k + 180;
                    if (this.j) {
                        z = false;
                    }
                    return a(i2, z);
                }
                i2 = this.k;
                if (this.j) {
                    z = false;
                }
                return a(i2, z);
            case 2:
                if (a()) {
                    i2 = this.k;
                    if (this.j) {
                        z = false;
                    }
                    return a(i2, z);
                }
                i2 = this.k + 180;
                if (this.j) {
                    z = false;
                }
                return a(i2, z);
            default:
                return a(this.k + i, this.j);
        }
    }

    public com.android.gpuimage.g a(com.android.gpuimage.g gVar) {
        if (gVar.j) {
            b(1);
        }
        return b(gVar.k);
    }

    public com.android.gpuimage.g b() {
        if (a() && this.j) {
            return a((-this.k) + 180, true);
        }
        return a(-this.k, this.j);
    }

    public int c() {
        return this.k;
    }

    public float[] d() {
        if (this.j) {
            switch (this.k) {
                case 90:
                    return g;
                case 180:
                    return h;
                case 270:
                    return i;
                default:
                    return f;
            }
        }
        switch (this.k) {
            case 90:
                return c;
            case 180:
                return d;
            case 270:
                return e;
            default:
                return b;
        }
    }

    public float[] a(float f, float f2, float f3, float f4) {
        s.set(f, f3);
        t.set(f2, f3);
        u.set(f, f4);
        v.set(f2, f4);
        if (!this.j) {
            switch (this.k) {
                case 90:
                    a(s, t);
                    a(t, u);
                    a(u, v);
                    break;
                case 180:
                    a(s, v);
                    a(t, u);
                    break;
                case 270:
                    a(s, u);
                    a(t, u);
                    a(u, v);
                    break;
                default:
                    break;
            }
        }
        switch (this.k) {
            case 90:
                a(t, u);
                break;
            case 180:
                a(s, u);
                a(t, v);
                break;
            case 270:
                a(s, v);
                break;
            default:
                a(s, t);
                a(u, v);
                break;
        }
        w[0] = s.x;
        w[1] = s.y;
        w[2] = t.x;
        w[3] = t.y;
        w[4] = u.x;
        w[5] = u.y;
        w[6] = v.x;
        w[7] = v.y;
        return w;
    }

    private void a(PointF pointF, PointF pointF2) {
        float f = pointF2.x;
        float f2 = pointF2.y;
        pointF2.x = pointF.x;
        pointF2.y = pointF.y;
        pointF.x = f;
        pointF.y = f2;
    }
}
